package com.mapbar.ure.utils;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class TwoKeysHashMap<K0, K1, V> {
	Map<K0, Map<K1, V>> container = new HashMap<K0, Map<K1, V>>();

	public V get(K0 k0, K1 k1) {
		if (container.containsKey(k0)) {
			return container.get(k0).get(k1);
		} else {
			return null;
		}
	}

	public Set<K0> firstKeys() {
		return container.keySet();
	}

	public V put(K0 k0, K1 k1, V value) {
		if (container.containsKey(k0)) {
			return container.get(k0).put(k1, value);
		} else {
			container.put(k0, new HashMap<K1, V>());
			return container.get(k0).put(k1, value);
		}
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		for (K0 k0 : container.keySet()) {
			sb.append(k0.toString());
			sb.append("\n");
			for (K1 k1 : container.get(k0).keySet()) {
				sb.append("\t");
				sb.append(k1.toString());
				sb.append("===>");
				sb.append(container.get(k0).get(k1));
				sb.append("\n");
			}
		}
		return sb.toString();
	}

	public Map<K1, V> get(Integer k) {
		return container.get(k);
	}
}
